package com.module.app.arouter.service.impl

import android.app.Activity
import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.module.app.base.BaseActivity
import com.module.base.arouter.path.BasePath
import com.module.base.arouter.service.IBaseService
import com.module.base.utils.LogUtils

/**
 * Base 配置处理。
 */
@Route(path = BasePath.S_BASE_SERVICE)
class BaseServiceImpl : IBaseService {
    override fun init(context: Context?) {
    }

    /**
     * 重启App，用于崩溃重启
     */
    override fun restartApp(context: Context) {
        //界面被销毁
        val service = ARouter.getInstance().build(com.module.app.arouter.path.LauncherPath.S_LAUNChHER_SERVICE)
            .navigation()

        service?.let {
            val mLauncherService = service as com.module.app.arouter.service.ILauncherService;
            if (!mLauncherService.isWelcomeActivity) {
                LogUtils.e("重启启动")
                mLauncherService.startWelcome(context)
                return
            }
        }

    }

    /**
     * 跳转到登录
     */
    override fun startLogin(context: Context) {
        com.module.app.arouter.ArouterUtils.getLoginService()?.startLogin(context)
    }

    override fun getDefaultPushActivity(): Class<out Activity?> {
        val mILauncherService = com.module.app.arouter.ArouterUtils.getLauncherService()
        var mClass: Class<out Activity?> = BaseActivity::class.java
        if (mILauncherService != null) {
            mClass = mILauncherService.defaultPushActivity
        }
        return mClass
    }
}